package com.fesine.ch02.t2;

/**
 * 实例变量为非线程安全
 * 如需要线程安全，需要使用synchronized修饰
 * @Author: Fesine
 * @CreateDate:2016/6/27
 * @UpdateUser:修改人名称
 * @UpdateDate:2016/6/27
 * @UpdateRemark:修改具体的内容
 */
public class HasSelfPrivateNum {
    private int num = 0;
    synchronized public void addI(String username) {
        if (username.equals("a")) {
            num = 100;
            System.out.println("a set over!");
            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        } else {
            num =200;
            System.out.println("b set over!");
        }
        System.out.println(username+" num=" + num);
    }
}
